﻿#include "uploadfile.h"
#include "ui_uploadfile.h"

QString afiletype;
QString afilepath;
QStringList STRType;
QStringList STRName;
QStringList STRsys;

class ReadOnlyDelegate: public QItemDelegate
{

public:
    ReadOnlyDelegate(QWidget *parent = NULL):QItemDelegate(parent)
    {}

    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                          const QModelIndex &index) const override //final
    {
        Q_UNUSED(parent)
        Q_UNUSED(option)
        Q_UNUSED(index)
        return NULL;
    }
};

//获取CheckBox
QCheckBox* UploadFile::getCheckBox(QTableWidget*table,int row ,int column)
{
    QWidget* pWidget = 0;
    pWidget = table->cellWidget(row,column); //找到单元格
    QCheckBox *pCheckBox = 0;
    bool bNew = true;
    if(pWidget != 0) //
    {
        bNew = false;
    }
    if(bNew)
    {
        pWidget = new QWidget(table); //创建一个widget
        QHBoxLayout *hLayout = new QHBoxLayout(pWidget); //创建布局
        pCheckBox = new QCheckBox(pWidget);
        //根据objectName ,去拆解所属的tableWidget 、行、列
        pCheckBox->setObjectName(QString("%1_%2_%3_Itme").arg(table->objectName()).arg(row).arg(column));
        pCheckBox->setChecked(false);
        pCheckBox->setFont(table->font());
        pCheckBox->setFocusPolicy(Qt::NoFocus);
        pCheckBox->setStyle(QStyleFactory::create("fusion"));
        pCheckBox->setStyleSheet(QString(".QCheckBox {margin:3px;border:0px;}QCheckBox::indicator {width: %1px; height: %1px; }").arg(20));
        hLayout->addWidget(pCheckBox); //添加
        hLayout->setMargin(0); //设置边缘距离
        hLayout->setAlignment(pCheckBox, Qt::AlignCenter); //居中
        hLayout->setSpacing(0);
        pWidget->setLayout(hLayout); //设置widget的布局
        table->setCellWidget(row,column,pWidget);
    }
    QList<QCheckBox *> allCheckBoxs =  pWidget->findChildren<QCheckBox *>();
    allCheckBoxsval.append(pCheckBox);
    if(allCheckBoxs.size() > 0)
        pCheckBox = allCheckBoxs.first();
    return pCheckBox;
}
//处理CheckBox
QCheckBox* UploadFile::setCheckBox(QTableWidget*table,int row ,int column,bool checkd)
{
    QCheckBox *check = getCheckBox(table,row,column);

    if(check != 0) //
    {
        check->setChecked(checkd);
    }
    QCheckBox::connect(check,&QCheckBox::stateChanged,[=]{
        QString objectName = check->objectName();
        QStringList nameList = objectName.split("_");//拆解
        if(nameList.count() == 4)
        {
            QString tableName = nameList.at(0);//表格名称
            int row = nameList.at(1).toInt();//行
            int column = nameList.at(2).toInt();//列
            bool checked = check->isChecked();//是否被选中

            //知道了表格、行、列，就可以执行我们所需要的操作了。。。
            qDebug() << QString("%1表第%2行第%3列是否被选中：%4")
                            .arg(tableName).arg(row).arg(column).arg(checked?"是":"否");
            if(checked){
                if(row==0){
                    // 使用foreach循环遍历
                    foreach(QCheckBox *checkBoxval, allCheckBoxsval) {
                        checkBoxval->setChecked(true);
                    }
                    chefl=1;
                }else{
                    rowfl.append(row);
                }

            }else{
                if(row==0&&chefl==1){
                    // 使用foreach循环遍历
                    foreach(QCheckBox *checkBoxval, allCheckBoxsval) {
                        checkBoxval->setChecked(false);
                    }
                }else{
                    rowfl.removeAll(row);
                    chefl=0;
                    allCheckBoxsval[0]->setChecked(false);
                }
            }
        }
        qDebug()<<rowfl;
    });
    return check;
}

UploadFile::UploadFile(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UploadFile)
{
    ui->setupUi(this);
    this->setWindowModality(Qt::ApplicationModal);
    this->setAttribute(Qt::WA_QuitOnClose, false);
    ui->comboBox->blockSignals(true);
    ui->comboBox_2->blockSignals(true);
    kzyqname();
    jyfxyname();
    ui->comboBox->blockSignals(false);
    ui->comboBox_2->blockSignals(false);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->setColumnWidth(0,40);
    ui->tableWidget->setColumnWidth(1,190);
    ui->tableWidget->setColumnWidth(2,190);
    ui->tableWidget->setColumnWidth(3,190);
    QHeaderView *header = ui->tableWidget->verticalHeader();
    header->setHidden(true);// 隐藏行号
    this->resize(660,510);
    setAttribute(Qt::WA_QuitOnClose,false);
    this->setWindowTitle("上传文件");
}

UploadFile::~UploadFile()
{
    delete ui;
}

void UploadFile::showEvent(QShowEvent *event)
{
    filefl=false;
    ui->tableWidget->clear();
    allCheckBoxsval.clear();
    rowfl.clear();
    STRType.clear();
    STRName.clear();
    STRsys.clear();
    ui->lineEdit->clear();
    tab();
    for(int i=0;i<ui->tableWidget->rowCount();i++){
        ReadOnlyDelegate* readOnlyDelegate = new ReadOnlyDelegate(this);
        ui->tableWidget->setItemDelegateForColumn(i, readOnlyDelegate);
    }
}
// 扩增仪器
void UploadFile::kzyqname(){
    QString sql="SELECT Name FROM ItemCode WHERE DicCode=13 ";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QStringList sanames;
    query.exec(sql);
    while (query.next()) {
        QString column1Value = query.value("Name").toString();
        sanames.append(column1Value);
    }
    query.clear();

    ui->comboBox->clear();
    ui->comboBox->addItems(sanames);

    sql="SELECT Name FROM ItemCode WHERE DicCode=13 and IsDefault=1 ";
    query.exec(sql);

    QStringList sanames2;
    while (query.next()) {
        QString column1Value = query.value("Name").toString();
        sanames2.append(column1Value);
    }
    query.clear();

    if(sanames2.length()>0){
        ui->comboBox->setCurrentText(sanames2[0]);
    }
}
// 扩增仪器改变
void UploadFile::on_comboBox_currentTextChanged(const QString &arg1)
{
    QString sql = "UPDATE ItemCode SET IsDefault =0 WHERE DicCode=13 ";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    if (!query.exec(sql)) {
        qDebug() << "Error:" << query.lastError().text();
    }
    sql = QString("UPDATE ItemCode SET IsDefault ='1' WHERE DicCode='%1' and Name= '%2'").arg("13",arg1);
    if (!query.exec(sql)) {
        qDebug() << "Error:" << query.lastError().text();
    }
}
// 基因分析仪
void UploadFile::jyfxyname(){
    QString sql="SELECT Name FROM ItemCode WHERE DicCode=14 ";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QStringList sanames;
    query.exec(sql);
    while (query.next()) {
        QString column1Value = query.value("Name").toString();
        sanames.append(column1Value);
    }
    query.clear();

    ui->comboBox_2->clear();
    ui->comboBox_2->addItems(sanames);

    sql="SELECT Name FROM ItemCode WHERE DicCode=14 and IsDefault=1 ";
    query.exec(sql);

    QStringList sanames2;
    while (query.next()) {
        QString column1Value = query.value("Name").toString();
        sanames2.append(column1Value);
    }
    query.clear();

    if(sanames2.length()>0){
        ui->comboBox_2->setCurrentText(sanames2[0]);
    }
}
// 基因分析仪改变
void UploadFile::on_comboBox_2_currentTextChanged(const QString &arg1)
{
    QString sql = "UPDATE ItemCode SET IsDefault =0 WHERE DicCode=14 ";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    if (!query.exec(sql)) {
        qDebug() << "Error:" << query.lastError().text();
    }
    sql = QString("UPDATE ItemCode SET IsDefault ='1' WHERE DicCode='%1' and Name= '%2'").arg("14",arg1);
    if (!query.exec(sql)) {
        qDebug() << "Error:" << query.lastError().text();
    }
}
// 取消按钮
void UploadFile::on_SaveBtn_2_clicked()
{
    this->close();
}
// 表格初始化
void UploadFile::tab(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql=QString("SELECT Code,Name FROM ItemCode WHERE DicCode='%1'").arg("15");
    QStringList typeval;
    QList<int> typecode;
    query.exec(sql);
    while (query.next()) {
        int column1Value=query.value("Code").toInt();
        QString column2Value = query.value("Name").toString();
        typeval.append(column2Value);
        typecode.append(column1Value);
    }
    ui->tableWidget->setRowCount(typeval.length()+1);
    ui->tableWidget->setColumnCount(4);
    QStringList header;
    header<<"□"<<"试剂盒类型"<<"试剂盒名称"<<"体系(μl)";
//    ui->tableWidget->setHorizontalHeaderLabels(header);
    ui->tableWidget->horizontalHeader()->hide();//取消列号()->hide();//取消行号
    setCheckBox(ui->tableWidget,0,0,false);
    QTableWidgetItem *item = new QTableWidgetItem();
    item->setText("试剂盒类型");
    item->setForeground(QBrush(QColor(255,255,255)));
    QTableWidgetItem *item2 = new QTableWidgetItem();
    item2->setText("试剂盒名称");
    item2->setForeground(QBrush(QColor(255,255,255)));
    QTableWidgetItem *item3 = new QTableWidgetItem();
    item3->setText("体系(μl)");
    item3->setForeground(QBrush(QColor(255,255,255)));
    ui->tableWidget->setItem(0,1,item);
    ui->tableWidget->setItem(0,2,item2);
    ui->tableWidget->setItem(0,3,item3);
    for(int i=1;i<typeval.length()+1;i++){
        setCheckBox(ui->tableWidget,i,0,false);
        ui->tableWidget->setItem(i,1,new QTableWidgetItem(typeval[i-1]));
        sql=QString("SELECT Name FROM ItemCode WHERE DicCode='%1'").arg(typecode[i-1]);
        QStringList nameval;
        query.exec(sql);
        while (query.next()) {
            QString column2Value = query.value("Name").toString();
            nameval.append(column2Value);
        }
        QComboBox *classBox = new QComboBox;
        classBox->addItems(nameval);
        ui->tableWidget->setCellWidget(i,2,classBox);
        sql=QString("SELECT Name FROM ItemCode WHERE DicCode='%1'").arg(19);
        QStringList txnames;
        query.exec(sql);
        while (query.next()) {
            QString column2Value = query.value("Name").toString();
            txnames.append(column2Value);
        }
        QComboBox *classBox2 = new QComboBox;
        classBox2->addItems(txnames);
        ui->tableWidget->setCellWidget(i,3,classBox2);
    }
    QColor skyBlue(173, 216, 230); // 或者使用QColor::fromRgb(0xADD8E6)如果你喜欢十六进制
    for (int column = 0; column < ui->tableWidget->columnCount(); ++column) {
        QTableWidgetItem *item = ui->tableWidget->item(0, column); // 获取第一行的每个单元格项
        if (!item) {
            // 如果单元格是空的，则创建一个新的项（可选，取决于你的需求）
            // 注意：这可能会改变单元格的编辑状态等，因此请根据你的需求谨慎使用
            item = new QTableWidgetItem();
            ui->tableWidget->setItem(0, column, item);
        }
        // 设置项的背景色（这将影响单元格内文本的背景）
        item->setBackground(QBrush(skyBlue));

        // 如果你想要设置整个单元格（包括没有文本的部分）的背景色，
        // 你可能需要考虑自定义委托或使用其他方法，因为Qt的标准API不直接支持这一点。

        // 但是，对于大多数用途来说，设置项的背景色已经足够了。
    }
    for (int row = 0; row < ui->tableWidget->rowCount(); ++row) {
        for (int col = 0; col < ui->tableWidget->columnCount(); ++col){
            QTableWidgetItem *item = new QTableWidgetItem();
            item=ui->tableWidget->item(row,col);
            if(item==nullptr){

            }else{
                ui->tableWidget->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
            }
        }
    }
}
// 文件选择
void UploadFile::on_pushButton_clicked()
{
#ifdef Q_OS_ANDROID

    DialogFileManager dfm(0);
    dfm.exec();
    QString remotePath = dfm.getResult();
    QString localPath = SMBManager::SMB2Local(remotePath);

    if(remotePath==""){
        return;
    }
    afilepath = localPath;
    SMBManager::I().downloadFile(remotePath, localPath);

#else
    afilepath = QFileDialog::getOpenFileName(this, tr("Open Excel file"), "", tr("Excel Files (*.xlsx *.xls)"));  // 获取 Excel 文件路径

#endif
    afiletype = ui->comboBox->currentText();
    QXlsx::Document xlsx(afilepath);
    QStringList sheetnames =xlsx.sheetNames();
    if (!afilepath.isEmpty()){
        ui->lineEdit->setText(afilepath);
        if(afiletype=="7500"){
            if(sheetnames.contains("Results")){
                xlsx.selectSheet("Results");
                QStringList title;
                for(int i=1;i<9;i++){
                    title.append(xlsx.read(8,i).toString());
                }
                qDebug()<<title;
                if(title[0]=="Well"&&title[1]=="Sample Name"&&title[2]=="Target Name"&&title[3]=="Task"&&title[4]=="Reporter"&&title[5]=="Quencher"&&title[6]=="Cт"&&title[7]=="Cт Mean"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择7500实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="7500线上"){
            if(sheetnames.contains("Standard Curve Result")){
                xlsx.selectSheet("Standard Curve Result");
                if(xlsx.read(26,2).toString()=="Well Position"&&xlsx.read(26,3).toString()=="Sample"&&xlsx.read(26,5).toString()=="Target"&&xlsx.read(26,6).toString()=="Dye"
                        &&xlsx.read(26,7).toString()=="Task"&&xlsx.read(26,11).toString()=="Cq"&&xlsx.read(26,12).toString()=="Cq Mean"&&xlsx.read(26,4).toString()=="Quantity"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择7500线上实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="鲲鹏"){
            if(sheetnames.contains("结果")){
                xlsx.selectSheet("结果");
                int colu=1;
                for(int i=1;i<xlsx.dimension().rowCount();i++){
                    QString celll = xlsx.read(i,2).toString();
                    if(celll=="孔"){
                        colu = i;
                        break;
                    }
                }
                qDebug()<<colu<<xlsx.dimension().rowCount();
                qDebug()<<xlsx.read(colu,2).toString()<<xlsx.read(colu,3).toString()<<xlsx.read(colu,4).toString()<<xlsx.read(colu,6).toString()<<xlsx.read(colu,5).toString()
                          <<xlsx.read(colu,7).toString()<<xlsx.read(colu,8).toString()<<xlsx.read(colu,14).toString();
                if(xlsx.read(colu,2).toString()=="孔"&&xlsx.read(colu,3).toString()=="样本名称"&&xlsx.read(colu,4).toString()=="检测项目"&&xlsx.read(colu,6).toString()=="荧光染料"
                        &&xlsx.read(colu,5).toString()=="检测类型"&&xlsx.read(colu,7).toString()=="Cq"&&xlsx.read(colu,8).toString()=="Cq平均值"&&xlsx.read(colu,14).toString()=="浓度"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择鲲鹏实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="Q5"){
            if(sheetnames.contains("结果分析")){
                xlsx.selectSheet("结果分析");
                if(xlsx.read(47,2).toString()=="反应孔位置"&&xlsx.read(47,4).toString()=="样本名"&&xlsx.read(47,5).toString()=="基因名称"&&xlsx.read(47,7).toString()=="报告基团"
                        &&xlsx.read(47,6).toString()=="任务"&&xlsx.read(47,9).toString()=="CRT"&&xlsx.read(47,10).toString()=="Crt 平均值"&&xlsx.read(47,12).toString()=="Quantity"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择Q5实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="Q5英文版"){
            if(sheetnames.contains("Results")){
                xlsx.selectSheet("Results");
                if(xlsx.read(47,2).toString()=="Well Position"&&xlsx.read(47,4).toString()=="Sample Name"&&xlsx.read(47,5).toString()=="Target Name"&&xlsx.read(47,7).toString()=="Reporter"
                        &&xlsx.read(47,6).toString()=="Task"&&xlsx.read(47,9).toString()=="CRT"&&xlsx.read(47,10).toString()=="Crt Mean"&&xlsx.read(47,12).toString()=="Quantity"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择Q5英文版实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="伯乐"){
            if(sheetnames.contains("0")){
                xlsx.selectSheet("0");
                if(xlsx.read(1,2).toString()=="Well"&&xlsx.read(1,3).toString()=="Fluor"&&xlsx.read(1,4).toString()=="Target"&&xlsx.read(1,5).toString()=="Content"&&
                        xlsx.read(1,6).toString()=="Sample"&&xlsx.read(1,8).toString()=="Cq"&&xlsx.read(1,9).toString()=="Cq Mean"&&xlsx.read(1,11).toString()=="Starting Quantity (SQ)"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择伯乐实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }else if(afiletype=="Design and Analysis-线下版"){
            if(sheetnames.contains("Standard Curve Result")){
                xlsx.selectSheet("Standard Curve Result");
                if(xlsx.read(25,2).toString()=="Well Position"&&xlsx.read(25,3).toString()=="Sample"&&xlsx.read(25,5).toString()=="Target"&&xlsx.read(25,8).toString()=="Reporter"
                        &&xlsx.read(25,7).toString()=="Task"&&xlsx.read(25,11).toString()=="Cq"&&xlsx.read(25,12).toString()=="Cq Mean"&&xlsx.read(25,4).toString()=="Quantity"){
                    filefl=true;
                }else{
                    tctsui =new tcts();
                    tctsui->infochange("提示","error","数据文件格式不正确！",false,true);
                    tctsui->show();
                    return;
                }
            }else{
                tctsui =new tcts();
                tctsui->infochange("提示","error","请选择Design and Analysis-线下版实验结果文件！",false,true);
                tctsui->show();
                return;
            }
        }
    }else{
        tctsui = new tcts();
        tctsui->infochange("提示","error","您选择的文件为空，请重新选择",false,true);
    }



}
// 分析按钮
void UploadFile::on_SaveBtn_clicked()
{
    if(ui->lineEdit->text()==""){
        tctsui = new tcts();
        tctsui->infochange("提示","info","请先上传定量仪器文件！",false,true);
        // 获取屏幕的中心点
        QRect screenGeometry = QApplication::desktop()->screenGeometry();
        int centerX = screenGeometry.center().x();
        int centerY = screenGeometry.center().y();
        int labelWidth = tctsui->sizeHint().width(); // 获取QLabel的建议大小
        int labelHeight = tctsui->sizeHint().height();
        int labelX = centerX-labelWidth/2;
        int labelY = centerY-labelHeight/2;
        tctsui->show();
        tctsui->move(labelX, labelY);
        return;
    }
    if(filefl){
        QList<int> rowflnew = rowfl.toSet().toList();
        if(rowflnew.length()==0){
            tctsui = new tcts();
            tctsui->infochange("提示","info","请选择分析模型！",false,true);
            // 获取屏幕的中心点
            QRect screenGeometry = QApplication::desktop()->screenGeometry();
            int centerX = screenGeometry.center().x();
            int centerY = screenGeometry.center().y();
            int labelWidth = tctsui->sizeHint().width(); // 获取QLabel的建议大小
            int labelHeight = tctsui->sizeHint().height();
            int labelX = centerX-labelWidth/2;
            int labelY = centerY-labelHeight/2;
            tctsui->show();
            tctsui->move(labelX, labelY);
            return;
        }
        for(int i=1;i<rowflnew.length()+1;i++){
            QSqlDatabase db = dbHelper::openConnection();
            QString sql=QString("SELECT ReagentKitType,ReagentKitName,System FROM DataAnalyseConfig WHERE ReagentKitType='%1' and ReagentKitName='%2' and System='%3' ")
                    .arg(ui->tableWidget->item(i,1)->text(),dynamic_cast<QComboBox *>(ui->tableWidget->cellWidget(i,2))->currentText(),dynamic_cast<QComboBox *>(ui->tableWidget->cellWidget(i,3))->currentText());
            QStringList namesfl;
            QSqlQuery query(db);
            query.exec(sql);
            while (query.next()) {
                QString namesf = query.value("ReagentKitType").toString();
                namesfl.append(namesf);
                STRType.append(query.value("ReagentKitType").toString());
                STRName.append(query.value("ReagentKitName").toString());
                STRsys.append(query.value("System").toString());
            }

            if(namesfl.length()==0){
                tctsui = new tcts();
                tctsui->infochange("提示","info","未找到匹配的模型！",false,true);
                // 获取屏幕的中心点
                QRect screenGeometry = QApplication::desktop()->screenGeometry();
                int centerX = screenGeometry.center().x();
                int centerY = screenGeometry.center().y();
                int labelWidth = tctsui->sizeHint().width(); // 获取QLabel的建议大小
                int labelHeight = tctsui->sizeHint().height();
                int labelX = centerX-labelWidth/2;
                int labelY = centerY-labelHeight/2;
                tctsui->show();
                tctsui->move(labelX, labelY);
                return;
            }
        }
        qDebug()<<STRType<<STRName<<STRsys;
        this->hide();
        emit changeTodetanalyWindow();
    }else{
        tctsui = new tcts();
        tctsui->infochange("提示","info","请确认文件路径是否正确！",false,true);
        // 获取屏幕的中心点
        QRect screenGeometry = QApplication::desktop()->screenGeometry();
        int centerX = screenGeometry.center().x();
        int centerY = screenGeometry.center().y();
        int labelWidth = tctsui->sizeHint().width(); // 获取QLabel的建议大小
        int labelHeight = tctsui->sizeHint().height();
        int labelX = centerX-labelWidth/2;
        int labelY = centerY-labelHeight/2;
        tctsui->show();
        tctsui->move(labelX, labelY);
        return;
    }

}
